************************************************************************************************************************************************************************
* This Stata 14.2 code reproduces the results of the cross-country regression analysis reported in:															************
* Mader, Matthias/Steiner, Nils: Party institutionalization and intra-party preference homogeneity, Zeitschrift für Vergleichende Politikwissenschaft.		************
************************************************************************************************************************************************************************

* How to reproduce all results
* 1.) Download data:
    *CCS 2016
	*Comparative Candidates Survey Module I – 2005-2013 [Dataset – cumulative file]. Distributed by FORS, Lausanne, 2016.
	*data available at http://forscenter.ch/de/daris-daten-und-forschungsinformationsservice/datenservice/spezialprojekte/comparative-candidate-survey-ccs/
	*Data set: 620_CCS_Data_Wave1_v3.1.dta

	*CMP
	*Volkens, Andrea / Lehmann, Pola / Matthieß, Theres / Merz, Nicolas / Regel, Sven with Werner, Annika (2016): The Manifesto Data Collection. Manifesto Project (MRG / CMP / MARPOR). Version 2016a. Berlin: Wissenschaftszentrum Berlin für Sozialforschung (WZB).
	*data available at https://manifestoproject.wzb.eu/datasets
	*Data set: MPDataset_MPDS2016a_stata14.dta
		
	*DALP
	*Kitschelt, Herbert. 2013. Dataset of the Democratic Accountability and Linkages Project (DALP). Duke University, https://sites.duke.edu/democracylinkage.
	*data available at https://sites.duke.edu/democracylinkage
	*Data set: partylevel_20130907.dta
	
* 2.) Save all files (data sets and Stata do-files) in one folder and specify this folder as the working directory.
* 3.) If neccessary, install missing ados. Ados used: agrm, estout, fre. Graph scheme used: plottig.
			* ssc install estout
			* ssc install fre
			* ssc install agrm
			* ssc install blindschemes, replace all
	
* 4.) Execute code using Stata 14.2.

* change working directory to the folder in which you saved the data sets and do-files (if necessary)
* cd "XXX"

* change general settings (to those used for our analysis)
	clear all	
	set more off, perm
	version 14.2
	set scheme plottig

	
	
	
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
********************************************************* Recoding and processing of data **********************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************	


****************************************************************************************************************************************************************
************************** Recoding of CCS data ****************************************************************************************************************
****************************************************************************************************************************************************************
	*** load Comparative Candidates Survey data set
		use "620_CCS_Data_Wave1_v4.0.dta", clear
  
  
	************************** General variables ***********************************
  
	**** Rename year and country variables
		gen year=t3
		gen countryID=t1

	*** Label country identifier			
		label define countryID ///
		1 "Australia" ///
		2 "Switzerland" ///
		3 "Germany" ///
		4 "Ireland" ///
		5 "Greece" ///
		6 "Finland" ///
		7 "Belgium" ///
		8 "Netherlands" ///
		9 "Canada" ///
		10 "Portugal" ///
		11 "Estonia" ///
		12 "Iceland" ///
		13 "Hungary" ///
		14 "Austria" ///
		15 "Sweden" ///
		16 "Denmark" ///
		17 "Romania" ///
		18 "Czech Republic" ///
		19 "Norway" ///
		20 "New Zealand" ///
		21 "Italy" ///
		22 "Malta" ///
		23 "United Kingdom"
		label value countryID countryID	
			
	*** Create unique election identifier
		gen elec_id=t1*10000+t3
		
	*** Label unique election identifier			
		label define elec_id ///
		12007 "Australia2007" ///
		12010 "Australia2010" ///
		22007 "Switzerland2007" ///
		22011 "Switzerland2011" ///
		32009 "Germany2009" /// 
		32005 "Germany2005" /// 
		42007 "Ireland2007" ///
		52007 "Greece2007" ///
		52009 "Greece2009" ///
		52012 "Greece2012" ///
		62007 "Finland2007" ///
		62011 "Finland2011" ///
		72007 "Belgium2007" ///
		72010 "Belgium2010" ///
		82006 "Netherlands2006" ///
		92008 "Canada2008" ///
		102009 "Portugal2009" ///
		102011 "Portugal2011" ///
		112011 "Estonia2011" ///
		122009 "Iceland2009" ///
		132010 "Hungary2010" ///
		142008 "Austria2008" ///
		152010 "Sweden2010" ///
		162011 "Denmark2011" ///
		172012 "Romania2012" ///
		182006 "CzechRepublic2006" ///
		192009 "Norway2009" ///
		202011 "NewZealand2011" ///
		212013 "Italy2013" ///
		222013 "Malta2013" ///
		232010 "UK2013"
		label value elec_id elec_id

	*** Create unique party-election-identifier (unique ID for a particular party at a specific election): eight digits: country identifier_year_party identifier.
		gen party=a1
		gen long partyelec_id=elec_id*100+party 
		format partyelec_id  %10.00f

	*** Drop those three surveys with next to complete missing issue batteries: Finland 2007, Canada 2008, New Zealand 2011
		drop if elec_id==62007 | elec_id==92008	| elec_id==202011
		
	*** Combine alliances
		* CSU to CDU -> CDU/CSU
		* GER2009
		replace partyelec_id=3200902 if partyelec_id==3200903
		* GER2009
		replace partyelec_id=3200502 if partyelec_id==3200503
		
		* BEL2007: spirit to spa -> spa/spirit
		replace partyelec_id=7200713 if partyelec_id==7200714
		
		* POR2011: PCP to PEV -> CDU
		replace partyelec_id=10201103 if partyelec_id==10201104
		
		* ROM2012
		* PSD to USL -> USL
		replace partyelec_id=17201205 if partyelec_id==17201201
		* PNL to USL -> USL
		replace partyelec_id=17201205 if partyelec_id==17201202
		* PC to USL -> USL
		replace partyelec_id=17201205 if partyelec_id==10201203

	*** Label party-election-identifier via code in separate do-file
		do "2 define party labels.do"

	*** Create string versions of identifier variables
		* Create string variable for country
		decode countryID, gen(country_string)
		* Create string variable for election
		decode elec_id, gen(elec_string)
		* Create string variable for partyelection
		decode partyelec_id, gen(partyelec_string)

	
	************************** Issue positions *********************************

	* Economic dimension
		*C2g. Providing a stable network of social security should be the prime goal of government.
		fre c2g
		gen ec1 = c2g
		
		*C2h. Income and wealth should be redistributed towards ordinary people.
		fre c2h
		gen ec2 = c2h
		
		*C2b. Politics should abstain from intervening in the economy.
		fre c2b
		recode c2b (1 = 5)(2 = 4)(3 = 3)(4 = 2)(5 = 1), gen(ec3)
		tab c2b ec3	

	* Socio-cultural dimension
		*C2a. Immigrants should be required to adjust to the customs of [country].
		fre c2a
		recode c2a (1 = 5)(2 = 4)(3 = 3)(4 = 2)(5 = 1), gen(soc1)
		tab c2a soc1

		*C2f. People who break the law should be given stiffer sentences.
		fre c2f
		recode c2f (1 = 5)(2 = 4)(3 = 3)(4 = 2)(5 = 1), gen(soc2)
		tab c2f soc2

		*C2m. Torturing a prisoner is never justified even if it might prevent a terrorist attack.
		fre c2m
		gen soc3=c2m
		tab c2m soc3
			
		*C2d. Same sex marriages should be prohibited by law.
		fre c2d
		recode c2d (1 = 5)(2 = 4)(3 = 3)(4 = 2)(5 = 1), gen(soc4)
		tab c2d soc4	
		
		*C2k. Women should be free to decide on matters of abortion.
		fre c2k
		gen soc5 = c2k
		tab c2k soc5	

	* European integration
		*C4. [Country's] membership of the EU good?
		fre c4
		recode c4 (1 = 2)(2 = 0)(3 = 1), gen(eu1)
		tab c4 eu1
		
		*C5. Opinion on European Unification - has already gon too far vs. should be pushed further.
		fre c5
		gen eu2 = c5
		tab c5 eu2
		
		*C6. How satisfied with the way democracy works in the EU?
		fre c6
		recode c6 (1 = 3)(2 = 2)(3 = 1)(4 = 0), gen(eu3)
		tab c6 eu3	
	
	* Left-right placements
		* Left-right self-placement
		fre c3
		gen ideo_ego = c3
		* Left-right party-placement
		fre c3a
		gen ideo_party = c3a 
	
	
	* Create additive indices (individual items recoded to common range)
		* economic
		gen econ_index=((ec1+ec2+ec3)-3)/12
		* socio-cultural 
		gen soc_index=((soc1+soc2+soc3+soc4+soc5)-5)/20
		* EU dimensions
		gen eu_index=((eu1/2)+(eu2/10)+(eu3/3))/3 
		* social justice issue
		gen sj_index=((ec1+ec2)-2)/8

	* Create disaggregated issue measures (with speaking variable names)
		gen protectenvironment = c2c
		
		
	************************** Value infusion items ****************************

	* "An MP in a conflict between the constituency voters and the position of the party should follow"
		fre d4a
		recode d4a (1=1) (2=0), gen(party_vs_voter)
		label define party_vs_voter 1 "party" 0 "voter"
		label values party_vs_voter party_vs_voter 
	* "An MP in a conflict between own opinion and the party position should follow"
		fre d4c
		recode d4c (1=0) (2=1), gen(party_vs_own)
		label define party_vs_own 1 "party" 0 "own"
		label values party_vs_own party_vs_own
	
		pwcorr party_vs_voter party_vs_own
	
	* summary index
		gen valueinfusion=(party_vs_voter+party_vs_own)/2
	
	* Compute standard deviations for single-item on environmental protection
		sort partyelec_id
	
		by partyelec_id: egen protectenvironment_partystd=sd(protectenvironment)
	
	
	********* Compute the CEES VAN DER EIJK (2001) agreement measure on environmental protection via the agrm-ado ********
	* Some preparations to get ado running
		* Drop cases with partyelec_id/A1=missing
		drop if partyelec_id==.
	
		* Shorter party-election-identifier variable name
		gen long pe_id=partyelec_id
		format pe_id  %10.00f
		
		* Save CCS recoding in progress
		save "DATA_CCS_in_progress.dta", replace

	*  C2c. Stronger measures should be taken to protect the environment.
		use "DATA_CCS_in_progress.dta", clear 	
		 gen environ_unst=protectenvironment
		 drop if protectenvironment_partystd==.
		 bysort pe_id: agrm environ_unst, gen(A) 
		 gen A_environ=.
		 levelsof partyelec_id, local(partyelec_id)
		 foreach party_elec of local partyelec_id {
				replace A_environ=A_environ_unst_pe_id`party_elec' if A_environ_unst_pe_id`party_elec'!=.
				drop A_environ_unst_pe_id`party_elec'
		 }	
		 pwcorr A_environ protectenvironment_partystd
		 keep partyelec_id A_environ

		save "DATA_A_environ.dta", replace

	
	*** Merge data on agreement on environment protection
		use "DATA_CCS_in_progress.dta", replace 
		merge m:m partyelec_id using "DATA_A_environ.dta", generate(A_environ_merge)

	
	*** save before collapse
		save "DATA_CCS_in_progress.dta", replace 
	
	
****************************************************************************************************************************************************************
************************** Collapse the dataset to party-election structure ************************************************************************************
****************************************************************************************************************************************************************
	* get mean positions, standard deviations and count of valid observations
	collapse (mean) econ_mean=econ_index sj_mean=sj_index soc_mean=soc_index eu_index_mean=eu_index A_environ ///
					year countryID elec_id ///
					valueinfusion /// 
					///
			  (sd)  econ_sd=econ_index sj_sd=sj_index soc_sd=soc_index eu_sd=eu_index ///
					///
			(count) N_candidates=party N_econ=econ_index N_sj=sj_index N_soc=soc_index N_eu=eu_index N_protectenvironment=protectenvironment ///
					N_valueinfusion=valueinfusion /// 
					, by (partyelec_id)

			
			
****************************************************************************************************************************************************************
************************** Recoding of party-election data *****************************************************************************************************
****************************************************************************************************************************************************************
					
	*** Flip standard deviation variables to compute homogeneity measures
		gen econ_sdr = -1*econ_sd
		gen soc_sdr = -1*soc_sd
		gen eu_sdr = -1*eu_sd
		gen sj_sdr = -1*sj_sd
		
	*** set minimum number of valid candidate positions for party to be included in analyis below (before standardization) to 10
		global minN 10		

	*** Standardize homogeneity measures 
		sum econ_sdr if N_econ>=$minN
		replace econ_sdr=. if N_econ<$minN
		replace econ_sdr=(econ_sdr-r(min))/(r(max)-r(min)) if N_econ>=$minN
		
		sum soc_sdr if N_soc>=$minN
		replace soc_sdr=. if N_soc<$minN
		replace soc_sdr=(soc_sdr-r(min))/(r(max)-r(min)) if N_soc>=$minN
		
		sum eu_sdr if N_eu>=$minN
		replace eu_sdr=. if N_eu<$minN
		replace eu_sdr=(eu_sdr-r(min))/(r(max)-r(min)) if N_eu>=$minN
		
		sum sj_sdr if N_sj>=$minN
		replace sj_sdr=. if N_sj<$minN
		replace sj_sdr=(sj_sdr-r(min))/(r(max)-r(min)) if N_sj>=$minN


	*** Label variables 
		*** Label value infusion (party loyalty)
			label define valueinfusion ///
				1 "high value infusion" ///
				0 "low value infusion" 
			label values valueinfusion valueinfusion
	
		*** label country and election identifier in collapsed CCS data set
			label value countryID countryID	
			label value elec_id elec_id
			decode countryID, gen(country_string)

	*** Create codes for merging with other party-level data
		*** Create Manifesto party code
			do "3 create Manifesto codes.do"
			label define Manifesto_code .a "party not included"
			label value party_id_Manifesto Manifesto_code

		*** Create party age variable (based on CSES and Wikipedia data)  *******
			do "4 create party age variables.do"

		*** Create DALP party code
			do "5 create DALP codes.do"
			label define DALP_code .a "party not included" .b "country not included in DALP" .c "mismatch between CCS and DALP"
			label value party_id_DALP DALP_code

		*** Save data set		
			save "DATA_collapsed_CCS_party_level.dta", replace

			
	
****************************************************************************************************************************************************************
************************** Recoding of Manifesto data **********************************************************************************************************
****************************************************************************************************************************************************************

	*** Open Manifesto data
		use "MPDataset_MPDS2016a_stata14.dta", clear
		
	*** Rename party identifier
		rename party party_id_Manifesto
		
	*** Manage electoral alliance: create new entries for CDU (Portuguese one); combine data for PEV + PCP
		* copy observations for PCP	
		expand 2 if date==201106 & party_id_Manifesto==35220
		expand 2 if date==200909 & party_id_Manifesto==35220
		* change partycode and partyname of copied observations
		replace party_id_Manifesto = 999999 in 3925
		replace party_id_Manifesto = 999999 in 3926
		replace partyname = "CDU: PCP Portuguese Communist Party + PEV: Ecologist Party 'The Greens'" in 3925
		replace partyname = "CDU: PCP Portuguese Communist Party + PEV: Ecologist Party 'The Greens'" in 3926
		* change variable values to missing
		foreach varname of varlist parfam-intpeace {
		replace `varname'=. if party_id_Manifesto==999999
		}
		* create a weight 
		* weight for the PCP
		gen weight_CDU=4 if party_id_Manifesto==35220
		* weight for the PEV
		replace weight_CDU=1 if party_id_Manifesto==35110
		* enter weighted means
		* 2009
		foreach varname of varlist total-intpeace {
		summarize `varname' [w=weight_CDU] if date==200909 & (party_id_Manifesto==35110 | party_id_Manifesto==35220)
		replace `varname'=r(mean) if party_id_Manifesto==999999 & date==200909
		}
		* 2011
		foreach varname of varlist total-intpeace {
		summarize `varname' [w=weight_CDU] if date==201106 & (party_id_Manifesto==35110 | party_id_Manifesto==35220)
		replace `varname'=r(mean) if party_id_Manifesto==999999 & date==201106
		}

	*** Some reorganisation of the Manifesto data
		gen year=year(edate)
		sort party_id_Manifesto year
		* drop Greece 2012 election in May 2012 (CCS data for Greece 2012 belongs to June 2012 election; prevent duplicate)
		drop if country==34 & date==201205
				
	*** Code variable: Percentage of votes gained by each party
		gen CMP_pervote=pervote/100 
		
	*** Code variable: Absolute number of seats won by each party or party bloc
		rename absseat CMP_absseat
		
	*** Code variable: Total number of seats in parliament
		rename totseats CMP_totseats
		
	*** Code variable: Grouping of political parties and alliances into the following party families
		rename parfam CMP_parfam
		
		recode CMP_parfam (10 = 10 "Ecologist") (20 = 20 "Communist") (30 = 30 "Social democratic") (40 = 40 "Liberal") ///
						  (50 = 50 "Christian democratic") (60 = 60 "Conservative") (70 = 70 "Nationalist") (80 90 95 = 100 "Others"), gen(CMP_parfam2)
		label variable CMP_parfam2 "Recoded CMP_parfam, i.e., with 'other' category" 

		gen green_d = .
		replace green_d = 1 if CMP_parfam2 == 10
		replace green_d = 0 if CMP_parfam2 != 10 & CMP_parfam2 != .
		label define green_d ///
			0 "Other" ///
			1 "Ecological parties"
		label values green_d green_d
		tab CMP_parfam2 green_d, mis

		gen left_d = .
		replace left_d = 1 if CMP_parfam2 == 20 | CMP_parfam2 == 30
		replace left_d = 0 if CMP_parfam2 != 20 & CMP_parfam2 != 30 & CMP_parfam2 != .
		label define left_d ///
			0 "Other" ///
			1 "Left parties"
		label values left_d left_d
		tab CMP_parfam2 left_d, mis

		gen right_d = .
		replace right_d = 1 if CMP_parfam2 == 50 | CMP_parfam2 == 60 | CMP_parfam2 == 70
		replace right_d = 0 if CMP_parfam2 != 50 & CMP_parfam2 != 60 & CMP_parfam2 != 70 & CMP_parfam2 != .
		label define right_d ///
			0 "Other" ///
			1 "Conservative parties"
		label values right_d right_d
		tab CMP_parfam2 right_d, mis
		
	*** Keep only relevant variables
		keep party_id_Manifesto CMP_* year green_d left_d right_d
	
	*** Save recoded Manifesto data set
		save "DATA_MPDataset_MPDS2016a_merge.dta", replace
	
	

****************************************************************************************************************************************************************
************************** Recoding of DALP party-level data ***************************************************************************************************
****************************************************************************************************************************************************************

	*** Open DALP data set
		use partylevel_20130907.dta, clear				

	*** Preparations for matching 
		gen party_id_DALP=_n				
		label define PARTY 1""				
		forvalues n = 1/506 {				
		local x = party[`n']				
		label define PARTY `n'"`x'", modify				
		}				
		label value party_id_DALP PARTY

	*** Recode variable: Party size (Average of a party’s vote shares in the most recent two national legislative elections before 2009.)
		fre partysize
		rename partysize DALP_partysize
		
	*** Recode variable: Policy orientation (Please indicate the extent to which parties seek to mobilize electoral support by emphasizing the attractiveness of the party’s positions on policy issues.)
		*[1] Not at all
		*[2] To a small extent
		*[3] To a moderate extent
		*[4] To a great extent
		fre e2
		gen DALP_policy=(e2-1)/3 
		fre DALP_policy
		label define DALP_policy_l ///
			1 "strong policy orientation" ///
			0 "weak policy orientation" 
		label values DALP_policy DALP_policy_l
		
	*** Recode variable: Nationalization of candidate selection (Which of the following four options best describes the following parties’ balance of power in selecting candidates for national legislative elections?)
		fre a5a
		*Recoded version of a5, with response categories:
		*[1] National party leaders control the process of candidate selections
		*[2] Regional/state-level party organizations control the process of candidate selections
		*[3] Selection is the outcome of bargaining between different levels 
		*[4] Local/municipal actors control the process of candidate selections
		*The party-level variable contains means of expert judgements for each party
		gen DALP_candselection = (4 - a5a)/3 
		fre DALP_candselection
		
		label define DALP_candselection_l ///
			1 "centralized selection" ///
			0 "decentralized selection"
		label values DALP_candselection DALP_candselection_l

	*** Recode variable: Nationalization of electoral strategy (Similarly, which of the following options best characterizes the process by which the following parties decide on electoral strategy, for example campaign platforms and slogans, coalition strategies, and campaign resource allocations?)
		fre a6a
		*Recoded version of a6, with response categories:
		*[1] Electoral Strategy is chosen by national party leaders with little participation from local or state level organizations.
		*[2] Electoral strategy is chosen by regional or state-level organizations.
		*[3] The choice of electoral strategy is the outcome of bargaining between the different levels of party organization.
		*[4] Electoral strategy is chosen by local or municipal level actors.
		rename a6a DALP_elecstrategy
		
	*** Recode variable: Presence of factions (In your opinion, do the following parties have stable factional groups in their National Conventions or Parliamentary Caucuses?)
		fre a7
		rename a7 DALP_factions 
		
		pwcorr a1 a2 a3
		
	*** Recode variable: Local offices
		fre a1
		*Do the following parties or their individual candidates maintain offices and paid staff at the local or municipal-level? If yes, are these offices and staff permanent or only during national elections?
		*[1] Yes, the party maintains permanent local offices in MOST districts
		*[2] Yes, the party maintains permanent local offices in SOME districts
		*[3] Yes, the party maintains local offices, but only during national elections
		*[4] No, the party does not maintain local offices
		*[99] Don’t know
		gen DALP_localoff = (4 - a1)/3
		fre DALP_localoff
		
		label define DALP_localoff ///
			1 "local offices in most districts" ///
			0 "no local offices"
		label values DALP_localoff DALP_localoff

	*** Recode variable: Local representatives 
		fre a3
		*Do the following parties have local intermediaries (e.g. neighborhood leaders, local notables, religious leaders) who operate in local constituencies on the parties’ behalf, and perform 
		*a variety of important tasks such as maintaining contact with large groups of voters, organizing electoral support and voter turnout, and distributing party resources to voters and supporters?
		*[1] Yes, they have local representatives in MOST constituencies
		*[2] Yes, they have local representatives in SOME constituencies
		*[3] No, they have almost no local representatives
		*[99] Don’t know
		gen DALP_localreps = (3 - a3)/2
		fre DALP_localreps	
		
		label define DALP_localreps ///
			1 "local representatives in most districts" ///
			0 "almost no local representatives"
		label values DALP_localreps DALP_localreps
				
	***Compute Bolleyer/Ruth base-level routinization
		gen DALP_routinization=(DALP_localoff+DALP_localreps)/2
		fre DALP_routinization
		
		label define DALP_routinization ///
			1 "high routinization" ///
			0 "low routinization"
		label values DALP_routinization DALP_routinization
		
	*** Keep only relevant variables
		keep DALP* party_id_DALP

	*** Save recoded DALP data set
		save "DATA_DALP_partylevel_merge.dta", replace

		
	
****************************************************************************************************************************************************************
************************** Merge, clean, and save data set *****************************************************************************************************
****************************************************************************************************************************************************************	

	*** Reopen collapsed CCS data
		use "DATA_collapsed_CCS_party_level.dta", clear
		
	*** Merge with Manifesto
		merge m:m party_id_Manifesto year using "DATA_MPDataset_MPDS2016a_merge.dta", generate(Manifesto_merge)
	*** Drop cases that are Manifesto only
		drop if Manifesto_merge==2

	*** Merge with DALP
		merge m:m party_id_DALP using "DATA_DALP_partylevel_merge.dta", generate(DALP_merge)
	*** Drop cases that are DALP only
		drop if DALP_merge==2

	*** Save final merged dataset
		sort partyelec_id
		save "DATA_final.dta", replace

			 

****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
***************************************************************** Analysis begins ******************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************	
	*** open processed data		 
	use "DATA_final.dta", clear

	*** set minimum number of valid candidate positions for party to be included in analyis below to 10
	global minN 10		
		
		
****************************************************************************************************************************************************************
************************** Descriptives ************************************************************************************************************************
****************************************************************************************************************************************************************		
	*** Summary statistics
	sum econ_sdr soc_sdr eu_sdr sj_sdr A_environ DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote

	
	***** Figure 2 --- Scatter plots and correlations *****

		* Economic dimension 
			* Routinization
			pwcorr econ_sdr DALP_routinization if N_econ>=$minN, sig obs
			twoway (scatter econ_sdr DALP_routinization, ytitle("Preference homogeneity", size(large)) ///
					xtitle("Party routinization", size(large)) ///
					xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
					yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
					(lfit econ_sdr DALP_routinization, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .13, N = 115", size(large))) if N_econ>=$minN, name(econ_routinization_log, replace) ysize(2) xsize(3)

			* Value infusion
			pwcorr econ_sdr valueinfusion if N_econ>=$minN, sig obs
			twoway (scatter econ_sdr valueinfusion, ytitle("Preference homogeneity", size(large)) ///
					xtitle("Value infusion", size(large)) ///
					xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
					yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
					(lfit econ_sdr valueinfusion, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .28, N = 168", size(large))) if N_econ>=$minN, name(econ_infusion, replace) ysize(2) xsize(3)
		
		graph combine econ_routinization_log econ_infusion, title(Economic dimension, size(large)) name(econ, replace) xsize(10)
				
				
		* Socio-cultural dimension 
			* Routinization
			pwcorr soc_sdr DALP_routinization if N_soc>=$minN, sig obs	
			twoway (scatter soc_sdr DALP_routinization, ytitle("Preference homogeneity", size(large)) ///
					xtitle("Party routinization", size(large)) ///
					xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
					yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
					(lfit soc_sdr DALP_routinization, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = -.05, N = 111", size(large))) if N_soc>=$minN, name(soc_routinization, replace) ysize(2) xsize(3)

		*Social dimension 
			* Value infusion
			pwcorr soc_sdr valueinfusion if N_soc>=$minN, sig obs
			twoway (scatter soc_sdr valueinfusion, ytitle("Preference homogeneity", size(large)) ///
					xtitle("Value infusion", size(large)) ///
					xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
					yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
					(lfit soc_sdr valueinfusion, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .37, N = 175", size(large))) if N_soc>=$minN, name(soc_infusion, replace) ysize(2) xsize(3)
				
		graph combine soc_routinization soc_infusion, title(Sociocultural dimension, size(large)) name(soc, replace) xsize(10)
		
		* EU dimension 
			* Routinization
			pwcorr eu_sdr DALP_routinization if N_eu>=$minN, sig obs	
			twoway (scatter eu_sdr DALP_routinization, ytitle("Preference homogeneity", size(large)) ///
					xtitle("Party routinization", size(large)) ///
					xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
					yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
					(lfit eu_sdr DALP_routinization, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .29, N = 93", size(large))) if N_eu>=$minN, name(eu_routinization, replace) ysize(2) xsize(3)

			* Value infusion
			pwcorr eu_sdr valueinfusion if N_eu>=$minN, sig obs
			twoway (scatter eu_sdr valueinfusion, ytitle("Preference homogeneity", size(large)) ///
					xtitle("Value infusion", size(large)) ///
					xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
					yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
					(lfit eu_sdr valueinfusion, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .24, N = 127", size(large))) if N_eu>=$minN, name(eu_infusion, replace) ysize(2) xsize(3)
				
		graph combine eu_routinization eu_infusion, title(European integration, size(large)) name(eu, replace) xsize(10)
		
	
		* Combine to one figure
		graph combine econ soc eu, rows(3) iscale(0.5) ysize(6) name(figure2, replace)
		graph export Figure2.png, width(4000) replace
		graph export Figure2.pdf, replace



	
****************************************************************************************************************************************************************
************************** Main regression analysis ************************************************************************************************************
****************************************************************************************************************************************************************


	***** Table 4 --- Regression without interaction *****
		*** H1: Weakly institutionalized parties are more heterogeneous than strongly institutionalized parties.

		* Model 1: economic dimension
		xtreg econ_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_econ>=$minN, fe i(elec_id)
		quietly eststo econ_sdr
		
			* create a dummy to mark observations included in at least one of the regressions
			gen included=0
			replace included=1 if e(sample) & included==0
	
		* Model 2: socio-cultural dimension
		xtreg soc_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_soc>=$minN, fe i(elec_id)
		quietly eststo soc_sdr
		
			replace included=1 if e(sample) & included==0
		
		* Model 3: EU dimension
		xtreg eu_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_eu>=$minN, fe i(elec_id)
		quietly eststo eu_sdr

			replace included=1 if e(sample) & included==0

		* keep only cases included in at least one of the regressions
		keep if included==1
		* order variables (such that order corresponds to table A8 in the online appendix with raw descriptive data) 
		order included elec_id partyelec_id DALP_routinization valueinfusion N_candidates econ_sdr soc_sdr eu_sdr
			
		save "DATA_final.dta", replace
	
	 	* Model 4: pooled issue model 
			* convert dataset to stacked format before running the regression 	 
					gen count = _n
					expand 3
					bysort count: gen obs_issue = _n
					label define obs_issue 1 "econ" 2 "cult" 3 "EU"
					label values obs_issue obs_issue
					
					gen homogeneity = econ_sdr if obs_issue == 1
					replace homogeneity = soc_sdr if obs_issue == 2
					replace homogeneity = eu_sdr if obs_issue == 3

					gen issue_n=.
					replace issue_n=N_econ if obs_issue == 1
					replace issue_n=N_soc if obs_issue == 2
					replace issue_n=N_eu if obs_issue == 3


			xtreg homogeneity i.obs_issue c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN, fe i(elec_id)
			quietly eststo pool
		
		* Write stored estimates in Table 4
		esttab econ_sdr soc_sdr eu_sdr pool ///
		using Table4.rtf, b(%8.2f) se(%8.2f) star(* 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
					 coeflabels(DALP_routinization "Party routinization" ///
							    valueinfusion "Value infusion" ///
								DALP_policy "Policy orientation" ///
								DALP_candselection "Centralization of selection" ///
								CMP_pervote "Party size" ///
								party_age2_log "Party age (log)" ///
							   _cons "Constant") ///
				mtitles("Economic dimension" "Sociocultural dimension" "EU integration" "Pooled issues") nonumbers replace /// 	
				addnotes("Notes: ")

		 * save stacked version of the data
		 save "DATA_final_stacked", replace
	
	  
	  
  	***** Figure 3 --- Interactions between party family and routinization/value infusion *****
		*** H2: The difference in homogeneity between weakly and strongly institutionalized parties 
		***     should be smaller with regard to constitutive issues than with regard to secondary issues.
		
		* open dataset with normal structure again
			use "DATA_final.dta", clear
	
		*** Environment --- Ecological parties
	
			* Routinization
			xtreg A_environ c.DALP_routinization##i.green_d CMP_pervote party_age2_log if N_protectenvironment>=$minN, fe i(elec_id)	
			quietly eststo A_environ_1
			sum DALP_routinization if e(sample), detail
			
			margins, at(DALP_routinization=(0 (.01) 1) green_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) ///
				title("") ///
				text(1.1 .5 "Ecological parties", size(large)) text(.5 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.2)) ///
				ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("environ1", replace) ysize(2) xsize(3) 
			
			replace included=1 if e(sample) & included==0
		
			* Value infusion
			xtreg A_environ c.valueinfusion##i.green_d CMP_pervote party_age2_log if N_protectenvironment>=$minN, fe i(elec_id)	
			quietly eststo A_environ_2
			sum valueinfusion if e(sample), detail
			
			margins, at(valueinfusion=(0 (.01) 1) green_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) ///
				title("") ///
				text(1.1 .5 "Ecological parties", size(large)) text(.5 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.2)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("environ2", replace) ysize(2) xsize(3) 
			
			replace included=1 if e(sample) & included==0

		graph combine environ1 environ2, title(Environment protection, size(large)) name(environ, replace) xsize(10) 

	
		*** Social justice --- left parties
	
			* Routinization
			xtreg sj_sdr c.DALP_routinization##i.left_d CMP_pervote party_age2_log if N_sj>=$minN, fe i(elec_id)	
			quietly eststo sj_sdr_1
			sum DALP_routinization if e(sample), detail
			
			margins, at(DALP_routinization=(0 (.01) 1) left_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0)  lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) ///
				title("") ///
				text(.82 .5 "Left parties", size(large)) text(.4 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.05)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("sj_sdr1", replace) ysize(2) xsize(3) 
				
			replace included=1 if e(sample) & included==0
		
			* Value infusion
			xtreg sj_sdr c.valueinfusion##i.left_d CMP_pervote party_age2_log if N_sj>=$minN, fe i(elec_id)	
			quietly eststo sj_sdr_2
			sum valueinfusion if e(sample), detail
			
			margins, at(valueinfusion=(0 (.01) 1) left_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8) lcolor(gs5)) ci1opts(color(gs5)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// 
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.82 .5 "Left parties", size(large)) text(.4 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("sj_sdr2", replace) ysize(2) xsize(3) 
			
			replace included=1 if e(sample) & included==0
			
			graph combine sj_sdr1 sj_sdr2, title(Social justice, size(large)) ycommon name(sj, replace) xsize(10) 

	* Combine graphs to Figure 3 and export
		graph combine environ sj, cols(1) imargin(zero) iscale(0.7) xsize(6) ycommon name(figure3, replace)
		graph export Figure3.png, width(4000) replace
		graph export Figure3.pdf, replace
		
	* Write stored estimates in Table A2
		esttab A_environ_1 A_environ_2 sj_sdr_1 sj_sdr_2 ///
		using TableA2.rtf, b(%8.2f) se(%8.2f) star(* 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
		drop(0.green_d 0.green_d#c.DALP_routinization 0.green_d#c.valueinfusion ///
			 0.left_d 0.left_d#c.DALP_routinization 0.left_d#c.valueinfusion ///
			 ) ///
			coeflabels(DALP_routinization "Party routinization" ///
			1.green_d "Green parties" ///
			1.green_d#c.DALP_routinization "Green parties * Party routinization" ///
			valueinfusion "Value infusion" ///
			CMP_pervote "Party size" ///
			1.green_d#c.valueinfusion "Green parties * Value infusion" ///
			1.left_d "Left parties" ///
			1.left_d#c.DALP_routinization "Left parties * Party routinization" ///
			1.left_d#c.valueinfusion "Left party * Value infusion" ///
			party_age2_log "Party age (log)" ///
			_cons "Constant") ///
		mtitles("Environment" "Environment" "Social justice" "Social justice") nonumbers replace ///
		addnotes("Notes: ")
		
	*** list included countries and elections
		tab countryID if included==1
		tab elec_id if included==1
	

	
	***** Figure 4 --- Interactions between policy-seeking and routinization/value infusion *****
		* re-open stacked data
		use "DATA_final_stacked", clear	
		
		* Policy orientation
		*** H3: The difference in homogeneity between weakly and strongly institutionalized parties should be smaller among policy-seeking parties.

			*** interactions between policy-seeking and routinization
			xtreg homogeneity i.obs_issue c.DALP_routinization##c.DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN , fe i(elec_id)
				quietly eststo m1
				sum DALP_policy DALP_routinization if e(sample), detail
			
			margins, at(DALP_routinization=(0 (.01) 1) DALP_policy=(0.6666667 1))   // set DALP_policy to 5th and 95. percentile (of observed data in the estimation)
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.88 .5 "Strong policy orientation", size(large)) text(.22 .5 "Weak policy orientation", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("index1", replace)  ysize(2) xsize(3) 

			replace included=1 if e(sample) & included==0
		
		
			*** interactions between policy-seeking and value infusion
			xtreg homogeneity i.obs_issue c.valueinfusion##c.DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN , fe i(elec_id)
				quietly eststo m2
				sum DALP_policy valueinfusion if e(sample), detail

			margins, at(valueinfusion=(0 (.01) 1) DALP_policy=(.6470588 1))       	// set DALP_policy to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.88 .5 "Strong policy orientation", size(large)) text(.33 .5 "Weak policy orientation", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("index2", replace) ysize(2) xsize(3) 
			
				replace included=1 if e(sample) & included==0
		
		graph combine index1 index2, title(Policy orientation, size(medlarge)) ycommon iscale(0.65) xsize(7) name(figure4a, replace) 

		
		* Centralization of candidate selection
		*** H4: The difference in homogeneity between weakly and strongly institutionalized parties 
		***     should be less pronounced among parties with centralized selection and nomination processes.

			*** interactions between centralization of selection and routinization
			xtreg homogeneity i.obs_issue c.DALP_routinization##c.DALP_candselection DALP_policy CMP_pervote party_age2_log if issue_n>=$minN , fe i(elec_id)
				quietly eststo m3
				sum DALP_candselection DALP_routinization if e(sample), detail
	
			margins, at(DALP_routinization=(0 (.01) 1) DALP_candselection=(0.1 0.8)) // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.9 .5 "Centralized selection", size(large)) text(.38 .5 "Decentralized selection", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("index1", replace)  ysize(2) xsize(3)
				
			replace included=1 if e(sample) & included==0
		
			*** interactions between centralization of selection and value infusion
			xtreg homogeneity i.obs_issue c.valueinfusion##c.DALP_candselection DALP_policy CMP_pervote party_age2_log if issue_n>=$minN , fe i(elec_id)
				quietly eststo m4
				sum DALP_candselection valueinfusion if e(sample), detail

			margins, at(valueinfusion=(0 (.01) 1) DALP_candselection=(.0877193 0.8))  // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.9 .5 "Centralized selection", size(large)) text(.35 .5 "Decentralized selection", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("index2", replace) ysize(2) xsize(3) 
					
				replace included=1 if e(sample) & included==0
		
			graph combine index1 index2, title(Centralization of selection, size(medlarge)) ycommon iscale(0.65) xsize(7) name(figure4b, replace) 

		
		* Combine graphs to Figure 4 and export
			graph combine figure4a figure4b, col(1) imargin(tiny)
			graph export Figure4.png, width(4000) replace
			graph export Figure4.pdf, replace

		* Write stored estimates in Table A3
			esttab m1 m2 m3 m4 ///
			using TableA3.rtf, b(%8.2f) se(%8.2f) star(* 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
			coeflabels(DALP_routinization "Party routinization" ///
				DALP_policy "Policy orientation" ///
				c.DALP_routinization#c.DALP_policy "Party routinization * policy orientation" ///
				DALP_candselection "Candidate selection" ///
				CMP_pervote "Party size" ///
				valueinfusion "Value infusion" ///
				c.valueinfusion#c.DALP_policy "Value infusion * policy orientation" ///
				c.DALP_routinization#c.DALP_candselection "Party routinization * candidate selection" ///
				c.valueinfusion#c.DALP_candselection "Value infusion * candidate selection" ///
				party_age2_log "Party age (log)" ///
				_cons "Constant") ///
			nonumbers replace ///
			addnotes("Notes: ")
	
	
	
****************************************************************************************************************************************************************
************************** Robustness 1: Both interactions in one model ****************************************************************************************
****************************************************************************************************************************************************************
		
	***** Both interactions for party routinization in one model *****
		xtreg homogeneity c.DALP_routinization##c.DALP_candselection c.DALP_routinization##c.DALP_policy CMP_pervote party_age2_log i.obs_issue , fe i(elec_id)
			sum DALP_routinization DALP_candselection DALP_policy if e(sample), detail
		
			margins, at(DALP_routinization=(0 (.01) 1) DALP_policy=(0.6666667 1)) // set DALP_policy to 5th and 95. percentile (of observed data in the estimation)
			marginsplot, ///
			level(83) ///
			plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
			plot2opts(mcolor(gs0)  lcolor(black)) ci2opts(color(gs0)) ///
			xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
			ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
			title("") ///
			text(.88 .5 "Strong policy orientation", size(large)) text(.22 .5 "Weak policy orientation", size(large) color(gs8)) ///
			addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
			ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
			legend(off) ///
			name("rout_both_policy", replace) ysize(2) xsize(3) 

			margins, at(DALP_routinization=(0 (.01) 1) DALP_candselection=(0.1 0.8)) // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
			level(83) ///
			plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
			plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
			xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
			ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
			title("") ///
			text(.9 .5 "Centralized selection", size(large)) text(.38 .5 "Decentralized selection", size(large) color(gs8)) ///
			addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
			ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
			legend(off) ///
			name("rout_both_centr", replace) ysize(2) xsize(3) 
					
			graph combine rout_both_policy  rout_both_centr, ycommon iscale(0.75) xsize(9) name(routinization_onemodel, replace) 
			graph export FigureA1.png, width(4000) replace

	
	* Both interactions for value infusion in one model		
		xtreg homogeneity c.valueinfusion##c.DALP_candselection c.valueinfusion##c.DALP_policy CMP_pervote party_age2_log i.obs_issue, fe i(elec_id)
			sum valueinfusion DALP_candselection DALP_policy if e(sample), detail
		
			margins, at(valueinfusion=(0 (.01) 1) DALP_policy=(0.6666667 1)) // set DALP_policy to 5th and 95. percentile (of observed data in the estimation)
			marginsplot, ///
			level(83) ///
			plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
			plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
			xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
			ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
			title("") ///
			text(.88 .5 "Strong policy orientation", size(large)) text(.33 .5 "Weak policy orientation", size(large) color(gs8)) ///
			addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 30) axis(2)) ylabel(none, axis(2)) ///
			ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
			legend(off) ///
			name("valinf_both_policy", replace) ysize(2) xsize(3) 
			
			margins, at(valueinfusion=(0 (.01) 1) DALP_candselection=(0.1 0.8)) // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
			level(83) ///
			plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
			plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
			xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
			ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
			title("") ///
			text(.9 .5 "Centralized selection", size(large)) text(.35 .5 "Decentralized selection", size(large) color(gs8)) ///
			addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 30) axis(2)) ylabel(none, axis(2)) ///
			ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
			legend(off) ///
			name("valinf_both_centr", replace)  ysize(2) xsize(3) 
			
			graph combine valinf_both_policy valinf_both_centr, ycommon iscale(0.75) xsize(9) name(valinf_onemodel, replace)  
			graph export FigureA2.png, width(4000) replace
	
	
	
****************************************************************************************************************************************************************
************************** Robustness 2: Multilevel random effect models fitted with restricted maximum likelihood *********************************************
****************************************************************************************************************************************************************
		
	* write program for multilevel analysis that add ICC and BIC to stored estimates 
			capture program drop add_icc_and_bic
			program add_icc_and_bic
			   estat ic
				matrix define fitmatrix=r(S)
				scalar bic=fitmatrix[1,6]
				estadd scalar bic=bic
				estat icc
				scalar icc=r(icc2)
				estadd scalar icc=icc
			end
	
	
	*** Table A4 --- Regression without interaction ***
		
		* open datset with normal structure again
		use "DATA_final.dta", clear

		* Model 1: economic dimension		
		mixed econ_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_econ>=$minN || countryID: || elec_id: , reml stddeviations
				add_icc_and_bic
		quietly eststo econ_sdr

		* Model 2: socio-cultural dimension
		mixed soc_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_soc>=$minN || countryID: || elec_id: , reml stddeviations
				add_icc_and_bic
		quietly eststo soc_sdr
	
		* Model 3: EU dimension
		mixed eu_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_eu>=$minN || countryID: || elec_id: , reml stddeviations
				add_icc_and_bic
		quietly eststo eu_sdr

	 	* Model 4: pooled issue model 
		* open stacked dataset
		use "DATA_final_stacked", clear

		mixed homogeneity i.obs_issue c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN || countryID: || elec_id: , reml stddeviations
				add_icc_and_bic
		quietly eststo pool
			
		* Write stored estimates in Table 4a
		esttab econ_sdr soc_sdr eu_sdr pool ///
		using TableA4.rtf, b(%8.2f) se(%8.2f) star(* 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
				coeflabels(DALP_routinization "Party routinization" ///
							   valueinfusion "Value infusion" ///
								DALP_policy "Policy orientation" ///
								DALP_candselection "Centralization of selection" ///
								CMP_pervote "Party size" ///
								 party_age2_log "Party age (log)" ///
							   _cons "Constant") ///
				mtitles("Economic dimension" "Sociocultural dimension" "EU integration" "Pooled issues") nonumbers replace /// 	
				addnotes("Notes: ") ///
				scalars(icc)
			

	 ***** Figure A3 --- Version of figure 3 based on multilevel random effect models, i. e. interactions between party family and routinization/value infusion *****
		 * open datset with normal structure again
		  use "DATA_final.dta", clear

	  	*** Environment --- Ecological parties
	
			* Routinization
			mixed A_environ c.DALP_routinization##i.green_d CMP_pervote party_age2_log if N_protectenvironment>=$minN || countryID: || elec_id: , reml stddeviations
			quietly eststo A_environ_1
			sum DALP_routinization if e(sample), detail
			
			margins, at(DALP_routinization=(0 (.01) 1) green_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(1.1 .5 "Ecological parties", size(large)) text(.5 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.2)) ///
				ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("environ1", replace) ysize(2) xsize(3) 
			
			replace included=1 if e(sample) & included==0
		
			* Value infusion
			mixed A_environ c.valueinfusion##i.green_d CMP_pervote party_age2_log if N_protectenvironment>=$minN || countryID: || elec_id: , reml stddeviations
			quietly eststo A_environ_2
			sum valueinfusion if e(sample), detail
			
			margins, at(valueinfusion=(0 (.01) 1) green_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(1.1 .5 "Ecological parties", size(large)) text(.5 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.2)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("environ2", replace) ysize(2) xsize(3) 
			
			replace included=1 if e(sample) & included==0

		graph combine environ1 environ2, title(Environment protection, size(large)) name(environ, replace) xsize(10) 


		*** Social justice --- left parties
			* Routinization
			mixed sj_sdr c.DALP_routinization##i.left_d CMP_pervote party_age2_log if N_sj>=$minN || countryID: || elec_id: , reml stddeviations
			quietly eststo sj_sdr_1
			sum DALP_routinization if e(sample), detail
			
			margins, at(DALP_routinization=(0 (.01) 1) left_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0)  lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.82 .5 "Left parties", size(large)) text(.4 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("sj_sdr1", replace) ysize(2) xsize(3) 
				
			replace included=1 if e(sample) & included==0
		
			* Value infusion
			mixed sj_sdr c.valueinfusion##i.left_d CMP_pervote party_age2_log if N_sj>=$minN || countryID: || elec_id: , reml stddeviations
			quietly eststo sj_sdr_2
			sum valueinfusion if e(sample), detail
			
			margins, at(valueinfusion=(0 (.01) 1) left_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8) lcolor(gs5)) ci1opts(color(gs5)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.82 .5 "Left parties", size(large)) text(.4 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("sj_sdr2", replace) ysize(2) xsize(3) 
			
			replace included=1 if e(sample) & included==0
	
		graph combine sj_sdr1 sj_sdr2, title(Social justice, size(large)) ycommon name(sj, replace) xsize(10) 

	* Combine graphs to Figure A3 and export
	graph combine environ sj, cols(1) imargin(zero) iscale(0.7) xsize(6) ycommon name(figure2, replace)
	graph export FigureA3.png, width(4000) replace
				

		
*** Figure A4 --- Interactions between policy-seeking and routinization/value infusion
	* re-open stacked data
		use "DATA_final_stacked", clear	
			
	* Policy orientation
	*** H3: The difference in homogeneity between weakly and strongly institutionalized parties should be smaller among policy-seeking parties.
		
		*** interactions between policy-seeking and routinization
		mixed homogeneity i.obs_issue c.DALP_routinization##c.DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN || countryID: || elec_id: , reml stddeviations
			quietly eststo m1
			sum DALP_policy DALP_routinization if e(sample), detail
		
		margins, at(DALP_routinization=(0 (.01) 1) DALP_policy=(0.6666667 1)) // set DALP_policy to 5th and 95th percentile (of observed data in the estimation)
		marginsplot, ///
			level(83) ///
			plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
			plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
			xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
			ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
			title("") ///
			text(.88 .5 "Strong policy orientation", size(large)) text(.22 .5 "Weak policy orientation", size(large) color(gs8)) ///
			addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
			ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
			legend(off) ///
			name("index1", replace) ysize(2) xsize(3) 


		*** interactions between policy-seeking and value infusion
		mixed homogeneity i.obs_issue c.valueinfusion##c.DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN || countryID: || elec_id: , reml stddeviations
			quietly eststo m2
			sum DALP_policy valueinfusion if e(sample), detail

		margins, at(valueinfusion=(0 (.01) 1) DALP_policy=(.6470588 1))  // set DALP_policy to 5th and 95th percentile (of observed data in the estimation)
		marginsplot, ///
			level(83) ///
			plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
			plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
			xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
			ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
			title("") ///
			text(.88 .5 "Strong policy orientation", size(large)) text(.33 .5 "Weak policy orientation", size(large) color(gs8)) ///
			addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
			ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
			legend(off) ///
			name("index2", replace) ysize(2) xsize(3) 
		
	graph combine index1 index2, title(Policy orientation, size(medlarge)) ycommon iscale(0.65) xsize(7) name(figureA4a, replace) 
 

	* Centralization of candidate selection
	*** H4: The difference in homogeneity between weakly and strongly institutionalized parties 
	***     should be less pronounced among parties with centralized selection and nomination processes.
			
		*** interactions between centralization of selection and routinization
		mixed homogeneity i.obs_issue c.DALP_routinization##c.DALP_candselection DALP_policy CMP_pervote party_age2_log if issue_n>=$minN || countryID: || elec_id: , reml stddeviations
			quietly eststo m3
			sum DALP_candselection DALP_routinization if e(sample), detail
		
		margins, at(DALP_routinization=(0 (.01) 1) DALP_candselection=(0.1 0.8)) // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
		marginsplot, ///
			level(83) ///
			plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
			plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
			xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
			ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
			title("") ///
			text(.9 .5 "Centralized selection", size(large)) text(.38 .5 "Decentralized selection", size(large) color(gs8)) ///
			addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
			ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
			legend(off) ///
			name("index1", replace)  ysize(2) xsize(3) 
			
		*** interactions between centralization of selection and value infusion
		mixed homogeneity i.obs_issue c.valueinfusion##c.DALP_candselection DALP_policy CMP_pervote party_age2_log if issue_n>=$minN || countryID: || elec_id: , reml stddeviations
			quietly eststo m4
			sum DALP_candselection valueinfusion if e(sample), detail

		margins, at(valueinfusion=(0 (.01) 1) DALP_candselection=(.0877193 0.8))  // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
		marginsplot, ///
			level(83) ///
			plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
			plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
			xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
			ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
			title("") ///
			text(.9 .5 "Centralized selection", size(large)) text(.35 .5 "Decentralized selection", size(large) color(gs8)) ///
			addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
			ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
			legend(off) ///
			name("index2", replace) ysize(2) xsize(3) 
		

		* Combine graphs to Figure 4 and export
			graph combine index1 index2, title(Centralization of selection, size(medlarge)) ycommon iscale(0.65) xsize(7) name(figureA4b, replace) 
			graph combine figureA4a figureA4b, col(1) imargin(tiny)
			graph export FigureA4.png, width(4000) replace
			

			
****************************************************************************************************************************************************************
************************** Robustness 3: Baseline model with controls for party family (Table A5) **************************************************************
****************************************************************************************************************************************************************
	* fixed effect model 
		xtreg homogeneity i.obs_issue c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log ib60.CMP_parfam if issue_n>=$minN, fe i(elec_id)
		quietly eststo pool_fixed	
	* random effect model
		mixed homogeneity i.obs_issue c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log ib60.CMP_parfam if issue_n>=$minN || countryID: || elec_id: , reml stddeviations
				add_icc_and_bic
		quietly eststo pool_mixed
						
		esttab pool_fixed pool_mixed ///
		using TableA5.rtf, b(%8.2f) se(%8.2f) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
				coeflabels(DALP_routinization "Party routinization" ///
							   valueinfusion "Value infusion" ///
								DALP_policy "Policy orientation" ///
								DALP_candselection "Centralization of selection" ///
								CMP_pervote "Party size" ///
								party_age2_log "Party age (log)" ///
								10.CMP_parfam "Ecologist" ///
								20.CMP_parfam "Communist" ///
								30.CMP_parfam "Social-democrat" ///
								40.CMP_parfam "Liberal" ///
								50.CMP_parfam "Christian-democrat" ///
								60.CMP_parfam "Conservative" ///
								70.CMP_parfam "Nationalist" ///
								80.CMP_parfam "Agrarian" ///
								90.CMP_parfam "Ethnic-regional" ///
								95.CMP_parfam "Special issue" ///						  						   
							   _cons "Constant") ///						   
				mtitles("Economic dimension" "Sociocultural dimension" "EU integration" "Pooled issues") nonumbers replace /// 	
				addnotes("Notes: ") ///
				scalars(icc)	

				
				
****************************************************************************************************************************************************************
************************** Robustness 3: Models with only one election per country *****************************************************************************
****************************************************************************************************************************************************************
			
	***** Table A6 --- Regression without interaction *****
	use "DATA_final.dta", clear

	xtreg econ_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_econ>=$minN & elec_id!=22007 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)
	quietly eststo econ_sdr
	
	xtreg soc_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_soc>=$minN & elec_id!=22007 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)
	quietly eststo soc_sdr
		
	xtreg eu_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_eu>=$minN & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)
	quietly eststo eu_sdr

	use "DATA_final_stacked", clear
	
	xtreg homogeneity i.obs_issue c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN & elec_id!=22007 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)
	quietly eststo pool
					
	esttab econ_sdr soc_sdr eu_sdr pool ///
	using TableA6.rtf, b(%8.2f) se(%8.2f) star(* 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
			coeflabels(DALP_routinization "Party routinization" ///
						   valueinfusion "Value infusion" ///
							DALP_policy "Policy orientation" ///
							DALP_candselection "Centralization of selection" ///
							CMP_pervote "Party size" ///
							 party_age2_log "Party age (log)" ///
						   _cons "Constant") ///
			mtitles("Economic dimension" "Sociocultural dimension" "EU integration" "Pooled issues") nonumbers replace /// 	
			addnotes("Notes: ")
	

	***** Figure A5 --- Version of Figure 3 with only last election per country, i.e interactions between party family and routinization/value infusion ***
		* open dataset with normal structure again
			use "DATA_final.dta", clear
	
		*** Environment --- Ecological parties
	
			* Routinization
			xtreg A_environ c.DALP_routinization##i.green_d CMP_pervote party_age2_log if N_protectenvironment>=$minN & elec_id!=22007 & elec_id!=32005 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)	
			quietly eststo A_environ_1
			sum DALP_routinization if e(sample), detail
			
			margins, at(DALP_routinization=(0 (.01) 1) green_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) ///
				title("") ///
				text(1.1 .5 "Ecological parties", size(large)) text(.5 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.2)) ///
				ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("environ1", replace) ysize(2) xsize(3) 
	
			* Value infusion
			xtreg A_environ c.valueinfusion##i.green_d CMP_pervote party_age2_log if N_protectenvironment>=$minN & elec_id!=22007 & elec_id!=32005 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)	
			quietly eststo A_environ_2
			sum valueinfusion if e(sample), detail
			
			margins, at(valueinfusion=(0 (.01) 1) green_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) ///
				title("") ///
				text(1.1 .5 "Ecological parties", size(large)) text(.5 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.2)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("environ2", replace) ysize(2) xsize(3) 
			
			graph combine environ1 environ2, title(Environment protection, size(large)) name(environ, replace) xsize(10) 

	
		*** Social justice --- left parties
	
			* Routinization
			xtreg sj_sdr c.DALP_routinization##i.left_d CMP_pervote party_age2_log if N_sj>=$minN & elec_id!=22007 & elec_id!=32005 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)	
			quietly eststo sj_sdr_1
			sum DALP_routinization if e(sample), detail
			
			margins, at(DALP_routinization=(0 (.01) 1) left_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0)  lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.82 .5 "Left parties", size(large)) text(.4 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("sj_sdr1", replace) ysize(2) xsize(3) 
				
			* Value infusion
			xtreg sj_sdr c.valueinfusion##i.left_d CMP_pervote party_age2_log if N_sj>=$minN & elec_id!=22007 & elec_id!=32005 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)	
			quietly eststo sj_sdr_2
			sum valueinfusion if e(sample), detail
			
			margins, at(valueinfusion=(0 (.01) 1) left_d=(0 1))
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8) lcolor(gs5)) ci1opts(color(gs5)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.82 .5 "Left parties", size(large)) text(.4 .5 "Other parties", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				ytitle(" ", axis(2))) ///
				legend(off) ///
				name("sj_sdr2", replace) ysize(2) xsize(3) 
			
			graph combine sj_sdr1 sj_sdr2, title(Social justice, size(large)) ycommon name(sj, replace) xsize(10) 

			
			graph combine environ sj, cols(1) imargin(zero) iscale(0.7) xsize(6) ycommon name(figureA4, replace)
			graph export FigureA5.png, width(4000) replace


	***** Figure A6 --- Version of Figure 4 with only one election per country --- Interactions between policy-seeking and routinization/value infusion *****
		* re-open stacked data
			use "DATA_final_stacked", clear	
		
		* Policy orientation

			*** interactions between policy-seeking and routinization
			xtreg homogeneity i.obs_issue c.DALP_routinization##c.DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN & elec_id!=22007 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)
				quietly eststo m1
				sum DALP_policy DALP_routinization if e(sample), detail
			
			margins, at(DALP_routinization=(0 (.01) 1) DALP_policy=(0.6666667 1)) // set DALP_policy to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.88 .5 "Strong policy orientation", size(large)) text(.22 .5 "Weak policy orientation", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("index1", replace) ysize(2) xsize(3) 
	
			*** interactions between policy-seeking and value infusion
			xtreg homogeneity i.obs_issue c.valueinfusion##c.DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN & elec_id!=22007 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)
				quietly eststo m2
				sum DALP_policy valueinfusion if e(sample), detail

			margins, at(valueinfusion=(0 (.01) 1) DALP_policy=(0.6666667 1))  // set DALP_policy to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.88 .5 "Strong policy orientation", size(large)) text(.33 .5 "Weak policy orientation", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("index2", replace) ysize(2) xsize(3) 
			
			graph combine index1 index2, title(Policy orientation, size(medlarge)) ycommon iscale(0.65) xsize(7) name(figureA6a, replace) 

			
		* Centralization of candidate selection
			*** interactions between centralization of selection and routinization
			xtreg homogeneity i.obs_issue c.DALP_routinization##c.DALP_candselection DALP_policy CMP_pervote party_age2_log if issue_n>=$minN & elec_id!=22007 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)
				quietly eststo m3
				sum DALP_candselection DALP_routinization if e(sample), detail
	
			margins, at(DALP_routinization=(0 (.01) 1) DALP_candselection=(.1777778 0.8)) // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.9 .5 "Centralized selection", size(large)) text(.38 .5 "Decentralized selection", size(large) color(gs8)) ///
				addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("index1", replace)  ysize(2) xsize(3)
		
			*** interactions between centralization of selection and value infusion
			xtreg homogeneity i.obs_issue c.valueinfusion##c.DALP_candselection DALP_policy CMP_pervote party_age2_log if issue_n>=$minN & elec_id!=22007 & elec_id!=52007 & elec_id!=52009 & elec_id!=72007 & elec_id!=102009, fe i(elec_id)
				quietly eststo m4
				sum DALP_candselection valueinfusion if e(sample), detail

			margins, at(valueinfusion=(0 (.01) 1) DALP_candselection=(.1666667 .8222222))  // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
			marginsplot, ///
				level(83) ///
				plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
				plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
				xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
				ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
				title("") ///
				text(.9 .5 "Centralized selection", size(large)) text(.35 .5 "Decentralized selection", size(large) color(gs8)) ///
				addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
				ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
				legend(off) ///
				name("index2", replace) ysize(2) xsize(3) 
		
	
		* Combine graphs to Figure A6 and export
			graph combine index1 index2, title(Centralization of selection, size(medlarge)) ycommon iscale(0.65) xsize(7) name(figureA6b, replace) 
			graph combine figureA6a figureA6b, col(1) imargin(tiny)
			graph export FigureA6.png, width(4000) replace	
			
			

****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
************************** Robustness 4: Excluding candidates who thought they could not win *******************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
		* Repeat the procedure from above using only candidates who thought they had some chance to win * 
		
		
		*** load Comparative Candidates Survey data set
			use "620_CCS_Data_Wave1_v4.0.dta", clear
		
				
				************************** General variables ***********************************
			  
				**** Rename year and country variables
					gen year=t3
					gen countryID=t1

				*** Label country identifier			
					label define countryID ///
					1 "Australia" ///
					2 "Switzerland" ///
					3 "Germany" ///
					4 "Ireland" ///
					5 "Greece" ///
					6 "Finland" ///
					7 "Belgium" ///
					8 "Netherlands" ///
					9 "Canada" ///
					10 "Portugal" ///
					11 "Estonia" ///
					12 "Iceland" ///
					13 "Hungary" ///
					14 "Austria" ///
					15 "Sweden" ///
					16 "Denmark" ///
					17 "Romania" ///
					18 "Czech Republic" ///
					19 "Norway" ///
					20 "New Zealand" ///
					21 "Italy" ///
					22 "Malta" ///
					23 "United Kingdom"
					label value countryID countryID	
						
				*** Create unique election identifier
					gen elec_id=t1*10000+t3
					
				*** Label unique election identifier			
					label define elec_id ///
					12007 "Australia2007" ///
					12010 "Australia2010" ///
					22007 "Switzerland2007" ///
					22011 "Switzerland2011" ///
					32009 "Germany2009" /// 
					32005 "Germany2005" /// 
					42007 "Ireland2007" ///
					52007 "Greece2007" ///
					52009 "Greece2009" ///
					52012 "Greece2012" ///
					62007 "Finland2007" ///
					62011 "Finland2011" ///
					72007 "Belgium2007" ///
					72010 "Belgium2010" ///
					82006 "Netherlands2006" ///
					92008 "Canada2008" ///
					102009 "Portugal2009" ///
					102011 "Portugal2011" ///
					112011 "Estonia2011" ///
					122009 "Iceland2009" ///
					132010 "Hungary2010" ///
					142008 "Austria2008" ///
					152010 "Sweden2010" ///
					162011 "Denmark2011" ///
					172012 "Romania2012" ///
					182006 "CzechRepublic2006" ///
					192009 "Norway2009" ///
					202011 "NewZealand2011" ///
					212013 "Italy2013" ///
					222013 "Malta2013" ///
					232010 "UK2013"
					label value elec_id elec_id

				*** Create unique party-election-identifier (unique ID for a particular party at a specific election): eight digits: country identifier_year_party identifier.
					gen party=a1
					gen long partyelec_id=elec_id*100+party 
					format partyelec_id  %10.00f

				*** Drop those three surveys with next to complete missing issue batteries: Finland 2007, Canada 2008, New Zealand 2011
					drop if elec_id==62007 | elec_id==92008	| elec_id==202011
					
				*** Combine alliances
					* CSU to CDU -> CDU/CSU
					* GER2009
					replace partyelec_id=3200902 if partyelec_id==3200903
					* GER2009
					replace partyelec_id=3200502 if partyelec_id==3200503
					
					* BEL2007: spirit to spa -> spa/spirit
					replace partyelec_id=7200713 if partyelec_id==7200714
					
					* POR2011: PCP to PEV -> CDU
					replace partyelec_id=10201103 if partyelec_id==10201104
					
					* ROM2012
					* PSD to USL -> USL
					replace partyelec_id=17201205 if partyelec_id==17201201
					* PNL to USL -> USL
					replace partyelec_id=17201205 if partyelec_id==17201202
					* PC to USL -> USL
					replace partyelec_id=17201205 if partyelec_id==10201203

				*** Label party-election-identifier via code in separate do-file
					do "2 define party labels.do"

				*** Create string versions of identifier variables
					* Create string variable for country
					decode countryID, gen(country_string)
					* Create string variable for election
					decode elec_id, gen(elec_string)
					* Create string variable for partyelection
					decode partyelec_id, gen(partyelec_string)

					
	*** Keep only candidates that thought they had some chance to win 
			fre b16
			bysort elec_id: fre b16
			keep if b16==2 | b16==3 | b16==4 | b16==5 

				
				************************** Issue positions *********************************

				* Economic dimension
					*C2g. Providing a stable network of social security should be the prime goal of government.
					fre c2g
					gen ec1 = c2g
					
					*C2h. Income and wealth should be redistributed towards ordinary people.
					fre c2h
					gen ec2 = c2h
					
					*C2b. Politics should abstain from intervening in the economy.
					fre c2b
					recode c2b (1 = 5)(2 = 4)(3 = 3)(4 = 2)(5 = 1), gen(ec3)
					tab c2b ec3	

				* Socio-cultural dimension
					*C2a. Immigrants should be required to adjust to the customs of [country].
					fre c2a
					recode c2a (1 = 5)(2 = 4)(3 = 3)(4 = 2)(5 = 1), gen(soc1)
					tab c2a soc1

					*C2f. People who break the law should be given stiffer sentences.
					fre c2f
					recode c2f (1 = 5)(2 = 4)(3 = 3)(4 = 2)(5 = 1), gen(soc2)
					tab c2f soc2

					*C2m. Torturing a prisoner is never justified even if it might prevent a terrorist attack.
					fre c2m
					gen soc3=c2m
					tab c2m soc3
						
					*C2d. Same sex marriages should be prohibited by law.
					fre c2d
					recode c2d (1 = 5)(2 = 4)(3 = 3)(4 = 2)(5 = 1), gen(soc4)
					tab c2d soc4	
					
					*C2k. Women should be free to decide on matters of abortion.
					fre c2k
					gen soc5 = c2k
					tab c2k soc5	

				* European integration
					*C4. [Country's] membership of the EU good?
					fre c4
					recode c4 (1 = 2)(2 = 0)(3 = 1), gen(eu1)
					tab c4 eu1
					
					*C5. Opinion on European Unification - has already gon too far vs. should be pushed further.
					fre c5
					gen eu2 = c5
					tab c5 eu2
					
					*C6. How satisfied with the way democracy works in the EU?
					fre c6
					recode c6 (1 = 3)(2 = 2)(3 = 1)(4 = 0), gen(eu3)
					tab c6 eu3	
				
				* Left-right placements
					* Left-right self-placement
					fre c3
					gen ideo_ego = c3
					* Left-right party-placement
					fre c3a
					gen ideo_party = c3a 
				
				
				* Create additive indices (individual items recoded to common range)
					* economic
					gen econ_index=((ec1+ec2+ec3)-3)/12
					* socio-cultural 
					gen soc_index=((soc1+soc2+soc3+soc4+soc5)-5)/20
					* EU dimensions
					gen eu_index=((eu1/2)+(eu2/10)+(eu3/3))/3 
					* social justice issue
					gen sj_index=((ec1+ec2)-2)/8

				* Create disaggregated issue measures (with speaking variable names)
					gen protectenvironment = c2c
					
					
				************************** Value infusion items ****************************

				* "An MP in a conflict between the constituency voters and the position of the party should follow"
					fre d4a
					recode d4a (1=1) (2=0), gen(party_vs_voter)
					label define party_vs_voter 1 "party" 0 "voter"
					label values party_vs_voter party_vs_voter 
				* "An MP in a conflict between own opinion and the party position should follow"
					fre d4c
					recode d4c (1=0) (2=1), gen(party_vs_own)
					label define party_vs_own 1 "party" 0 "own"
					label values party_vs_own party_vs_own
				
					pwcorr party_vs_voter party_vs_own
				
				* summary index
					gen valueinfusion=(party_vs_voter+party_vs_own)/2
				
				* Compute standard deviations for single-item on environmental protection
					sort partyelec_id
				
					by partyelec_id: egen protectenvironment_partystd=sd(protectenvironment)
				
				
				********* Compute the CEES VAN DER EIJK (2001) agreement measure on environmental protection via the agrm-ado ********
				* Some preparations to get ado running
					* Drop cases with partyelec_id/A1=missing
					drop if partyelec_id==.
				
					* Shorter party-election-identifier variable name
					gen long pe_id=partyelec_id
					format pe_id  %10.00f
					
					* Save CCS recoding in progress
					save "DATA_CCS_subset_in_progress.dta", replace

				*  C2c. Stronger measures should be taken to protect the environment.
					use "DATA_CCS_subset_in_progress.dta", clear 	
					 gen environ_unst=protectenvironment
					 drop if protectenvironment_partystd==.
					 bysort pe_id: agrm environ_unst, gen(A) 
					 gen A_environ=.
					 levelsof partyelec_id, local(partyelec_id)
					 foreach party_elec of local partyelec_id {
							replace A_environ=A_environ_unst_pe_id`party_elec' if A_environ_unst_pe_id`party_elec'!=.
							drop A_environ_unst_pe_id`party_elec'
					 }	
					 pwcorr A_environ protectenvironment_partystd
					 keep partyelec_id A_environ

					save "DATA_A_environ_subset.dta", replace

				
				*** Merge data on agreement on environment protection
					use "DATA_CCS_subset_in_progress.dta", replace 
					merge m:m partyelec_id using "DATA_A_environ_subset.dta", generate(A_environ_merge)

				
				*** save before collapse
					save "DATA_CCS_subset_in_progress.dta", replace 
				
				
			****************************************************************************************************************************************************************
			************************** Collapse the dataset to party-election structure ************************************************************************************
			****************************************************************************************************************************************************************
				* get mean positions, standard deviations and count of valid observations
				collapse (mean) econ_mean=econ_index sj_mean=sj_index soc_mean=soc_index eu_index_mean=eu_index A_environ ///
								year countryID elec_id ///
								valueinfusion /// 
								///
						  (sd)  econ_sd=econ_index sj_sd=sj_index soc_sd=soc_index eu_sd=eu_index ///
								///
						(count) N_candidates=party N_econ=econ_index N_sj=sj_index N_soc=soc_index N_eu=eu_index N_protectenvironment=protectenvironment ///
								N_valueinfusion=valueinfusion /// 
								, by (partyelec_id)


			****************************************************************************************************************************************************************
			************************** Recoding of party-election data *****************************************************************************************************
			****************************************************************************************************************************************************************
								
				*** Flip standard deviation variables to compute homogeneity measures
					gen econ_sdr = -1*econ_sd
					gen soc_sdr = -1*soc_sd
					gen eu_sdr = -1*eu_sd
					gen sj_sdr = -1*sj_sd
					
				*** set minimum number of valid candidate positions for party to be included in analyis below (before standardization) to 10
					global minN 10		

				*** Standardize homogeneity measures 
					sum econ_sdr if N_econ>=$minN
					replace econ_sdr=. if N_econ<$minN
					replace econ_sdr=(econ_sdr-r(min))/(r(max)-r(min)) if N_econ>=$minN
					
					sum soc_sdr if N_soc>=$minN
					replace soc_sdr=. if N_soc<$minN
					replace soc_sdr=(soc_sdr-r(min))/(r(max)-r(min)) if N_soc>=$minN
					
					sum eu_sdr if N_eu>=$minN
					replace eu_sdr=. if N_eu<$minN
					replace eu_sdr=(eu_sdr-r(min))/(r(max)-r(min)) if N_eu>=$minN
					
					sum sj_sdr if N_sj>=$minN
					replace sj_sdr=. if N_sj<$minN
					replace sj_sdr=(sj_sdr-r(min))/(r(max)-r(min)) if N_sj>=$minN


				*** Label variables 
					*** Label value infusion (party loyalty)
						label define valueinfusion ///
							1 "high value infusion" ///
							0 "low value infusion" 
						label values valueinfusion valueinfusion
				
					*** label country and election identifier in collapsed CCS data set
						label value countryID countryID	
						label value elec_id elec_id
						decode countryID, gen(country_string)

				*** Create codes for merging with other party-level data
					*** Create Manifesto party code
						do "3 create Manifesto codes.do"
						label define Manifesto_code .a "party not included"
						label value party_id_Manifesto Manifesto_code

					*** Create party age variable (based on CSES and Wikipedia data)  *******
						do "4 create party age variables.do"

					*** Create DALP party code
						do "5 create DALP codes.do"
						label define DALP_code .a "party not included" .b "country not included in DALP" .c "mismatch between CCS and DALP"
						label value party_id_DALP DALP_code

					*** Save data set		
						save "DATA_collapsed_CCS_subset_party_level.dta", replace

						

			****************************************************************************************************************************************************************
			************************** Merge, clean, and save data set, delete obsolete data sets **************************************************************************
			****************************************************************************************************************************************************************	
					
				*** Merge with Manifesto
					merge m:m party_id_Manifesto year using "DATA_MPDataset_MPDS2016a_merge.dta", generate(Manifesto_merge)
				*** Drop cases that are Manifesto only
					drop if Manifesto_merge==2

				*** Merge with DALP
					merge m:m party_id_DALP using "DATA_DALP_partylevel_merge.dta", generate(DALP_merge)
				*** Drop cases that are DALP only
					drop if DALP_merge==2

				*** Save final merged dataset
					sort partyelec_id
					save "DATA_subset_final.dta", replace
				

						 

			****************************************************************************************************************************************************************
			****************************************************************************************************************************************************************
			***************************************************************** Analysis begins ******************************************************************************
			****************************************************************************************************************************************************************
			****************************************************************************************************************************************************************	
				*** open processed data		 
				use "DATA_subset_final.dta", clear

				*** set minimum number of valid candidate positions for party to be included in analyis below to 10
				global minN 0		
					
					
			****************************************************************************************************************************************************************
			************************** Descriptives ************************************************************************************************************************
			****************************************************************************************************************************************************************		
				*** Summary statistics
				sum econ_sdr soc_sdr eu_sdr sj_sdr A_environ DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote

				
				***** Figure A7 --- Scatter plots and correlations *****

					* Economic dimension 
						* Routinization
						pwcorr econ_sdr DALP_routinization if N_econ>=$minN, sig obs
						twoway (scatter econ_sdr DALP_routinization, ytitle("Preference homogeneity", size(large)) ///
								xtitle("Party routinization", size(large)) ///
								xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
								yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
								(lfit econ_sdr DALP_routinization, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .13, N = 115", size(large))) if N_econ>=$minN, name(econ_routinization_log, replace) ysize(2) xsize(3)

						* Value infusion
						pwcorr econ_sdr valueinfusion if N_econ>=$minN, sig obs
						twoway (scatter econ_sdr valueinfusion, ytitle("Preference homogeneity", size(large)) ///
								xtitle("Value infusion", size(large)) ///
								xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
								yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
								(lfit econ_sdr valueinfusion, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .28, N = 168", size(large))) if N_econ>=$minN, name(econ_infusion, replace) ysize(2) xsize(3)
					
					graph combine econ_routinization_log econ_infusion, title(Economic dimension, size(large)) name(econ, replace) xsize(10)
							
							
					* Socio-cultural dimension 
						* Routinization
						pwcorr soc_sdr DALP_routinization if N_soc>=$minN, sig obs	
						twoway (scatter soc_sdr DALP_routinization, ytitle("Preference homogeneity", size(large)) ///
								xtitle("Party routinization", size(large)) ///
								xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
								yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
								(lfit soc_sdr DALP_routinization, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = -.05, N = 111", size(large))) if N_soc>=$minN, name(soc_routinization, replace) ysize(2) xsize(3)

					*Social dimension 
						* Value infusion
						pwcorr soc_sdr valueinfusion if N_soc>=$minN, sig obs
						twoway (scatter soc_sdr valueinfusion, ytitle("Preference homogeneity", size(large)) ///
								xtitle("Value infusion", size(large)) ///
								xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
								yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
								(lfit soc_sdr valueinfusion, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .37, N = 175", size(large))) if N_soc>=$minN, name(soc_infusion, replace) ysize(2) xsize(3)
							
					graph combine soc_routinization soc_infusion, title(Sociocultural dimension, size(large)) name(soc, replace) xsize(10)
					
					* EU dimension 
						* Routinization
						pwcorr eu_sdr DALP_routinization if N_eu>=$minN, sig obs	
						twoway (scatter eu_sdr DALP_routinization, ytitle("Preference homogeneity", size(large)) ///
								xtitle("Party routinization", size(large)) ///
								xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
								yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
								(lfit eu_sdr DALP_routinization, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .29, N = 93", size(large))) if N_eu>=$minN, name(eu_routinization, replace) ysize(2) xsize(3)

						* Value infusion
						pwcorr eu_sdr valueinfusion if N_eu>=$minN, sig obs
						twoway (scatter eu_sdr valueinfusion, ytitle("Preference homogeneity", size(large)) ///
								xtitle("Value infusion", size(large)) ///
								xscale(range(0 1) lcolor(none)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
								yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", angle(horizontal) labsize(large))) ///
								(lfit eu_sdr valueinfusion, lcolor(black) lwidth(.5) legend(off) text(1.05 .87 "r = .24, N = 127", size(large))) if N_eu>=$minN, name(eu_infusion, replace) ysize(2) xsize(3)
							
					graph combine eu_routinization eu_infusion, title(European integration, size(large)) name(eu, replace) xsize(10)
					
				
					* Combine to one figure
					graph combine econ soc eu, rows(3) iscale(0.5) ysize(6) name(figure2, replace)
					graph export FigureA7.png, width(4000) replace
					graph export FigureA7.pdf, replace



				
			****************************************************************************************************************************************************************
			************************** Main regression analysis ************************************************************************************************************
			****************************************************************************************************************************************************************


				***** Table A7 --- Regression without interaction *****
					*** H1: Weakly institutionalized parties are more heterogeneous than strongly institutionalized parties.

					* Model 1: economic dimension
					xtreg econ_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_econ>=$minN, fe i(elec_id)
					quietly eststo econ_sdr
					
						* create a dummy to mark observations included in at least one of the regressions
						gen included=0
						replace included=1 if e(sample) & included==0
				
					* Model 2: socio-cultural dimension
					xtreg soc_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_soc>=$minN, fe i(elec_id)
					quietly eststo soc_sdr
					
						replace included=1 if e(sample) & included==0
					
					* Model 3: EU dimension
					xtreg eu_sdr c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if N_eu>=$minN, fe i(elec_id)
					quietly eststo eu_sdr

						replace included=1 if e(sample) & included==0

					* keep only cases included in at least one of the regressions
					keep if included==1
					* order variables (such that order corresponds to table A8 in the online appendix with raw descriptive data) 
					order included elec_id partyelec_id DALP_routinization valueinfusion N_candidates econ_sdr soc_sdr eu_sdr
						
					save "DATA_subset_final.dta", replace
				
					* Model 4: pooled issue model 
						* convert dataset to stacked format before running the regression 	 
								gen count = _n
								expand 3
								bysort count: gen obs_issue = _n
								label define obs_issue 1 "econ" 2 "cult" 3 "EU"
								label values obs_issue obs_issue
								
								gen homogeneity = econ_sdr if obs_issue == 1
								replace homogeneity = soc_sdr if obs_issue == 2
								replace homogeneity = eu_sdr if obs_issue == 3

								gen issue_n=.
								replace issue_n=N_econ if obs_issue == 1
								replace issue_n=N_soc if obs_issue == 2
								replace issue_n=N_eu if obs_issue == 3


						xtreg homogeneity i.obs_issue c.DALP_routinization valueinfusion DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN, fe i(elec_id)
						quietly eststo pool
					
					* Write stored estimates in Table A7
					esttab econ_sdr soc_sdr eu_sdr pool ///
					using TableA7.rtf, b(%8.2f) se(%8.2f) star(* 0.05 ** 0.01 *** 0.001) varwidth(20) nogaps compress ///
								 coeflabels(DALP_routinization "Party routinization" ///
											valueinfusion "Value infusion" ///
											DALP_policy "Policy orientation" ///
											DALP_candselection "Centralization of selection" ///
											CMP_pervote "Party size" ///
											party_age2_log "Party age (log)" ///
										   _cons "Constant") ///
							mtitles("Economic dimension" "Sociocultural dimension" "EU integration" "Pooled issues") nonumbers replace /// 	
							addnotes("Notes: ")

					 * save stacked version of the data
					 save "DATA_subset_final_stacked", replace
				
				  
				  
				***** Figure A8 --- Interactions between party family and routinization/value infusion *****
					*** H2: The difference in homogeneity between weakly and strongly institutionalized parties 
					***     should be smaller with regard to constitutive issues than with regard to secondary issues.
					
					* open dataset with normal structure again
						use "DATA_subset_final.dta", clear
				
					*** Environment --- Ecological parties
				
						* Routinization
						xtreg A_environ c.DALP_routinization##i.green_d CMP_pervote party_age2_log if N_protectenvironment>=$minN, fe i(elec_id)	
						quietly eststo A_environ_1
						sum DALP_routinization if e(sample), detail
						
						margins, at(DALP_routinization=(0 (.01) 1) green_d=(0 1))
						marginsplot, ///
							level(83) ///
							plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
							plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
							xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
							ytitle("Preference homogeneity", size(large)) ///
							title("") ///
							text(1.1 .5 "Ecological parties", size(large)) text(.5 .5 "Other parties", size(large) color(gs8)) ///
							addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ///
							ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.2)) ///
							ytitle(" ", axis(2))) /// 
							legend(off) ///
							name("environ1", replace) ysize(2) xsize(3) 
						
						replace included=1 if e(sample) & included==0
					
						* Value infusion
						xtreg A_environ c.valueinfusion##i.green_d CMP_pervote party_age2_log if N_protectenvironment>=$minN, fe i(elec_id)	
						quietly eststo A_environ_2
						sum valueinfusion if e(sample), detail
						
						margins, at(valueinfusion=(0 (.01) 1) green_d=(0 1))
						marginsplot, ///
							level(83) ///
							plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
							plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
							xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
							ytitle("Preference homogeneity", size(large)) ///
							title("") ///
							text(1.1 .5 "Ecological parties", size(large)) text(.5 .5 "Other parties", size(large) color(gs8)) ///
							addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ///
							ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.2)) ///
							ytitle(" ", axis(2))) ///
							legend(off) ///
							name("environ2", replace) ysize(2) xsize(3) 
						
						replace included=1 if e(sample) & included==0

					graph combine environ1 environ2, title(Environment protection, size(large)) name(environ, replace) xsize(10) 

				
					*** Social justice --- left parties
				
						* Routinization
						xtreg sj_sdr c.DALP_routinization##i.left_d CMP_pervote party_age2_log if N_sj>=$minN, fe i(elec_id)	
						quietly eststo sj_sdr_1
						sum DALP_routinization if e(sample), detail
						
						margins, at(DALP_routinization=(0 (.01) 1) left_d=(0 1))
						marginsplot, ///
							level(83) ///
							plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
							plot2opts(mcolor(gs0)  lcolor(black)) ci2opts(color(gs0)) ///
							xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) ///
							ytitle("Preference homogeneity", size(large)) ///
							title("") ///
							text(.82 .5 "Left parties", size(large)) text(.4 .5 "Other parties", size(large) color(gs8)) ///
							addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
							ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) yscale(range(0 1.05)) ///
							ytitle(" ", axis(2))) ///
							legend(off) ///
							name("sj_sdr1", replace) ysize(2) xsize(3) 
							
						replace included=1 if e(sample) & included==0
					
						* Value infusion
						xtreg sj_sdr c.valueinfusion##i.left_d CMP_pervote party_age2_log if N_sj>=$minN, fe i(elec_id)	
						quietly eststo sj_sdr_2
						sum valueinfusion if e(sample), detail
						
						margins, at(valueinfusion=(0 (.01) 1) left_d=(0 1))
						marginsplot, ///
							level(83) ///
							plot1opts(mcolor(gs8) lcolor(gs5)) ci1opts(color(gs5)) ///
							plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
							xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// 
							ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
							title("") ///
							text(.82 .5 "Left parties", size(large)) text(.4 .5 "Other parties", size(large) color(gs8)) ///
							addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
							ytitle(" ", axis(2))) ///
							legend(off) ///
							name("sj_sdr2", replace) ysize(2) xsize(3) 
						
						replace included=1 if e(sample) & included==0
						
						graph combine sj_sdr1 sj_sdr2, title(Social justice, size(large)) ycommon name(sj, replace) xsize(10) 

				* Combine graphs to Figure A8 and export
					graph combine environ sj, cols(1) imargin(zero) iscale(0.7) xsize(6) ycommon name(figure3, replace)
					graph export FigureA8.png, width(4000) replace
					graph export FigureA8.pdf, replace
								
				*** list included countries and elections
					tab countryID if included==1
					tab elec_id if included==1
				

				
				***** Figure A9 --- Interactions between policy-seeking and routinization/value infusion *****
					* re-open stacked data
					use "DATA_subset_final_stacked", clear	
					
					* Policy orientation
					*** H3: The difference in homogeneity between weakly and strongly institutionalized parties should be smaller among policy-seeking parties.

						*** interactions between policy-seeking and routinization
						xtreg homogeneity i.obs_issue c.DALP_routinization##c.DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN , fe i(elec_id)
							quietly eststo m1
							sum DALP_policy DALP_routinization if e(sample), detail
						
						margins, at(DALP_routinization=(0 (.01) 1) DALP_policy=(0.6666667 1))   // set DALP_policy to 5th and 95. percentile (of observed data in the estimation)
						marginsplot, ///
							level(83) ///
							plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
							plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
							xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
							ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
							title("") ///
							text(.88 .5 "Strong policy orientation", size(large)) text(.22 .5 "Weak policy orientation", size(large) color(gs8)) ///
							addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
							ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
							legend(off) ///
							name("index1", replace)  ysize(2) xsize(3) 

						replace included=1 if e(sample) & included==0
					
					
						*** interactions between policy-seeking and value infusion
						xtreg homogeneity i.obs_issue c.valueinfusion##c.DALP_policy DALP_candselection CMP_pervote party_age2_log if issue_n>=$minN , fe i(elec_id)
							quietly eststo m2
							sum DALP_policy valueinfusion if e(sample), detail

						margins, at(valueinfusion=(0 (.01) 1) DALP_policy=(.6470588 1))       	// set DALP_policy to 5th and 95th percentile (of observed data in the estimation)
						marginsplot, ///
							level(83) ///
							plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
							plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
							xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
							ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
							title("") ///
							text(.88 .5 "Strong policy orientation", size(large)) text(.33 .5 "Weak policy orientation", size(large) color(gs8)) ///
							addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
							ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
							legend(off) ///
							name("index2", replace) ysize(2) xsize(3) 
						
							replace included=1 if e(sample) & included==0
					
					graph combine index1 index2, title(Policy orientation, size(medlarge)) ycommon iscale(0.65) xsize(7) name(figure4a, replace) 

					
					* Centralization of candidate selection
					*** H4: The difference in homogeneity between weakly and strongly institutionalized parties 
					***     should be less pronounced among parties with centralized selection and nomination processes.

						*** interactions between centralization of selection and routinization
						xtreg homogeneity i.obs_issue c.DALP_routinization##c.DALP_candselection DALP_policy CMP_pervote party_age2_log if issue_n>=$minN , fe i(elec_id)
							quietly eststo m3
							sum DALP_candselection DALP_routinization if e(sample), detail
				
						margins, at(DALP_routinization=(0 (.01) 1) DALP_candselection=(0.1 0.8)) // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
						marginsplot, ///
							level(83) ///
							plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
							plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
							xtitle("Party routinization", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
							ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
							title("") ///
							text(.9 .5 "Centralized selection", size(large)) text(.38 .5 "Decentralized selection", size(large) color(gs8)) ///
							addplot(hist DALP_routinization if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
							ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
							legend(off) ///
							name("index1", replace)  ysize(2) xsize(3)
							
						replace included=1 if e(sample) & included==0
					
						*** interactions between centralization of selection and value infusion
						xtreg homogeneity i.obs_issue c.valueinfusion##c.DALP_candselection DALP_policy CMP_pervote party_age2_log if issue_n>=$minN , fe i(elec_id)
							quietly eststo m4
							sum DALP_candselection valueinfusion if e(sample), detail

						margins, at(valueinfusion=(0 (.01) 1) DALP_candselection=(.0877193 0.8))  // set DALP_candselection to 5th and 95th percentile (of observed data in the estimation)
						marginsplot, ///
							level(83) ///
							plot1opts(mcolor(gs8)  lcolor(gs8)) ci1opts(color(gs8)) ///
							plot2opts(mcolor(gs0) lcolor(black)) ci2opts(color(gs0)) ///
							xtitle("Value infusion", size(large)) xscale(range(0 1)) xlabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large)) /// ///
							ytitle("Preference homogeneity", size(large)) yscale(range(0 1.05)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ///
							title("") ///
							text(.9 .5 "Centralized selection", size(large)) text(.35 .5 "Decentralized selection", size(large) color(gs8)) ///
							addplot(hist valueinfusion if e(sample), percent discrete yaxis(2) yscale(alt range(0 20) axis(2)) ylabel(none, axis(2)) ///
							ylabel(none, axis(2)) ylabel(0 "0" .2 ".2" .4 ".4" .6 ".6" .8 ".8" 1 "1", labsize(large) angle(horizontal)) ytitle(" ", axis(2))) /// 
							legend(off) ///
							name("index2", replace) ysize(2) xsize(3) 
								
							replace included=1 if e(sample) & included==0
					
						graph combine index1 index2, title(Centralization of selection, size(medlarge)) ycommon iscale(0.65) xsize(7) name(figure4b, replace) 

					
					* Combine graphs to Figure A9 and export
						graph combine figure4a figure4b, col(1) imargin(tiny)
						graph export FigureA9.png, width(4000) replace
						graph export FigureA9.pdf, replace

				
				
				
	********** Delete obsolete data sets
		!del DATA_A_environ.dta ///
			 DATA_CCS_in_progress.dta DATA_collapsed_CCS_party_level.dta ///
			 DATA_MPDataset_MPDS2016a_merge.dta ///
			 DATA_DALP_partylevel_merge.dta	
						
						
						
*****************************************************************************************************************************************************
****************************************************************** END ******************************************************************************
*****************************************************************************************************************************************************
	